<?php

namespace App\Models\Traits;

use Bouncer;
use App\Models\Area;

trait AuthQueryScope {

    //根据角色查询
    public function scopeAuth($query) {
        $user = auth()->user();
        $scope = $user->scope;

        if($scope) {
            $aids = Area::whereDescendantOf($scope)->get()->pluck('AreaId')->toArray();
            $query->whereIn('scope', $aids);
        }

        return $query;
    }


}
